﻿<phone:PhoneApplicationPage 
    x:Class="SaveFuel.MainPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml"
    xmlns:phone="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone"
    xmlns:shell="clr-namespace:Microsoft.Phone.Shell;assembly=Microsoft.Phone"
    xmlns:d="http://schemas.microsoft.com/expression/blend/2008"
    xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006"
    xmlns:controls="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls"
    xmlns:lang="clr-namespace:SaveFuel"
    xmlns:conv="clr-namespace:SaveFuel.Utility"
    xmlns:toolkit1="clr-namespace:Microsoft.Phone.Controls;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:toolkit2="clr-namespace:Microsoft.Phone.Controls.Primitives;assembly=Microsoft.Phone.Controls.Toolkit"
    xmlns:BingMap="clr-namespace:Microsoft.Phone.Controls.Maps;assembly=Microsoft.Phone.Controls.Maps"
    xmlns:Maps="clr-namespace:Microsoft.Maps.MapControl;assembly=Microsoft.Maps.MapControl"
    mc:Ignorable="d" d:DesignWidth="480" d:DesignHeight="696"
    FontFamily="{StaticResource PhoneFontFamilyNormal}"
    FontSize="{StaticResource PhoneFontSizeNormal}"
    Foreground="{StaticResource PhoneForegroundBrush}"
    SupportedOrientations="Portrait" Orientation="Portrait"
    shell:SystemTray.IsVisible="True">

    <!--xmlns:myNamespace="clr-namespace:SaveFuel;assembly=SaveFuel.DateTimeConverter"-->
    <!--<phone:PhoneApplicationPage.Resources>
        <ControlTemplate x:Key="PushpinControlTemplate1" TargetType="Maps:Pushpin">
            <Grid Height="116" Width="155">
                <Ellipse Fill="#FFA3A3BE" Stroke="Black" Margin="0"/>
                <Image Source="{Binding PinSource}"/>
            </Grid>
        </ControlTemplate>
    </phone:PhoneApplicationPage.Resources>-->

    <!--<UserControl.Resources>
        <myNamespace:DateTimeConverter x:Key="DateTimeConverter" />
    </UserControl.Resources>-->

    <phone:PhoneApplicationPage.Resources>
        <Style x:Key="DeleteButtonStyle" TargetType="Button">
            <Setter Property="Template">
                <Setter.Value>
                    <ControlTemplate TargetType="Button">
                        <Grid>
                            <Image x:Name="DeleteButtonImage" Source="Images/delete.png"/>
                            <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}"
                                              VerticalAlignment="{TemplateBinding VerticalContentAlignment}"
                                              Content="" />
                        </Grid>
                    </ControlTemplate>
                </Setter.Value>
            </Setter>
        </Style>
        <lang:LocalizedStrings x:Key="LocalizedResources"/>
        <conv:DateTimeConverter x:Key="MyDateTimeToStringConverter"/>

    </phone:PhoneApplicationPage.Resources>

    <!--LayoutRoot è la griglia radice in cui viene inserito tutto il contenuto della pagina-->
    <Grid x:Name="LayoutRoot" Background="Transparent" DataContext="{Binding Source={StaticResource LocalizedResources}}">

        <controls:Pivot Title="{Binding Path=LocalizedResources.ApplicationTitle}" x:Name="ApplicationTitle">
            <!--Elemento Pivot uno -->
            <controls:PivotItem x:Name="PivotItem1MainPage" Header="{Binding Path=LocalizedResources.PivotItem1MainPage}">
                <!--<ScrollViewer>-->
                <StackPanel>
                    <TextBlock x:Name="lbTotalDistance" 
                               Text="{Binding Path=LocalizedResources.lbTotalDistance}" />
                    <!--Margin="0,-5,0,-5"-->
                    <TextBox Name="tbTotalDistance" InputScope="Number" Loaded="tbTotalDistance_Loaded" GotFocus="tbTotalDistance_GotFocus" Tap="tbTotalDistance_Tap" IsReadOnly="True" />
<!--"{Binding Path=LocalizedResources.lbPrice, Source={StaticResource LocalizedStrings}}"-->
                    <TextBlock x:Name="lbPrice" Text="{Binding Path=LocalizedResources.lbPrice}" />
                    <TextBox Name="tbPrice" InputScope="Number" IsReadOnly="True" Loaded="tbPrice_Loaded" Tap="tbPrice_Tap" />

                    <TextBlock Name="lbMoneySpent" Text="{Binding Path=LocalizedResources.lbMoneySpent}" />
                    <TextBox Name="tbMoneySpent" InputScope="Number" IsReadOnly="True" Tap="tbMoneySpent_Tap" Loaded="tbMoneySpent_Loaded" />
                    
                    <Grid Margin="0,0,0,-15">
                        <Grid.RowDefinitions>
                            <RowDefinition />
                            <RowDefinition />
                        </Grid.RowDefinitions>
                        <Grid.ColumnDefinitions>
                            <ColumnDefinition Width="*" />
                            <ColumnDefinition Width="200" />
                        </Grid.ColumnDefinitions>

                        <TextBlock Grid.Row="0" Grid.Column="0" x:Name="lbVolume" Text="{Binding Path=LocalizedResources.lbVolume}" />
                        <TextBlock Grid.Row="1" Grid.Column="0"  x:Name="lbGasolina"  FontSize="40" TextAlignment="Center" />


                        <TextBlock Grid.Row="0" Grid.Column="1" x:Name="lbFull" Text="{Binding Path=LocalizedResources.lbFull}" HorizontalAlignment="Center" />
                        <toolkit1:ToggleSwitch Grid.Row="1" Grid.Column="1" Name="isFull" IsChecked="False" Margin="0,-10,0,0" />
                        <!--<CheckBox Grid.Row="1" Grid.Column="1" Name="isFull" IsChecked="False" Margin="0,0,0,0" HorizontalAlignment="Center" />-->
                    </Grid>
                    <TextBlock Height="30" x:Name="label_RefuelingDate" Text="{Binding Path=LocalizedResources.label_RefuelingDate}" />
                    <toolkit1:DatePicker Name="datePickerRefuelingDate" Margin="0,-5,0,-5"/>
                    <TextBlock x:Name="StatusTextBlock" FontSize="18" Margin="0,5,0,0" />
                </StackPanel>
                <!--</ScrollViewer>-->
            </controls:PivotItem>

            <!--Elemento Pivot due -->
            <controls:PivotItem x:Name="PivotItem2MainPage" Header="{Binding Path=LocalizedResources.PivotItem2MainPage}">
                <!-- Dettagli rifornimenti -->
                <ListBox x:Name="DetailsListBox" Margin="0,0,-12,0" Loaded="DetailsListBox_Loaded" ItemsSource="{Binding Supplies}">
                    <!--ItemsSource="{Binding Supplies}"-->
                    <ListBox.ItemTemplate>
                        <DataTemplate>
                            <Grid Width="470" x:Name="lbGrid">
                                <Grid.RowDefinitions>
                                    <RowDefinition />
                                    <RowDefinition />
                                </Grid.RowDefinitions>
                                <Grid.ColumnDefinitions>
                                    <ColumnDefinition Width="50" />
                                    <ColumnDefinition Width="130" />
                                    <ColumnDefinition Width="140" />
                                    <ColumnDefinition Width="150" />
                                </Grid.ColumnDefinitions>

                                <Image Grid.Row="0" Grid.Column="0" Grid.RowSpan="2" Source="{Binding FillUpImage}" Visibility="Visible" />

                                <StackPanel Grid.Row="0" Grid.Column="1" Orientation="Horizontal">
                                    <TextBlock Text="{Binding Money, StringFormat='N2'}" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}" />
                                    <TextBlock Name="tbCurrency" Text="{Binding MoneyUnit}" Margin="5,0,0,0" />
                                </StackPanel>
                                <StackPanel Grid.Row="0" Grid.Column="2" Orientation="Horizontal">
                                    <TextBlock Text="{Binding Price, StringFormat='N3'}" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}" />
                                    <TextBlock Name="tbCurrencyVolume" Text="{Binding PriceUnit}" Margin="5,0,0,0" />
                                </StackPanel>
                                <StackPanel Grid.Row="0" Grid.Column="3" Orientation="Horizontal">
                                    <TextBlock Text="{Binding Gasolina, StringFormat='N2'}" TextWrapping="NoWrap" Margin="12,0,0,0" Style="{StaticResource PhoneTextExtraLargeStyle}" />
                                    <TextBlock Name="tbVolume" Text="{Binding GasolinaUnit}" Margin="5,0,0,0" />
                                </StackPanel>
                                <StackPanel Grid.Row="1" Grid.Column="1" Orientation="Horizontal">
                                    <TextBlock Text="{Binding TotalDistance}" HorizontalAlignment="Right" TextWrapping="NoWrap" Margin="12,0,0,0" />
                                    <TextBlock Name="tbDistance" Text="{Binding DistanceUnit}" Margin="5,0,0,0" />
                                </StackPanel>
                                <StackPanel Grid.Row="1" Grid.Column="2" Orientation="Horizontal">
                                    <Image Source="{Binding GpsOn}" /> <!--ToolTipService.ToolTip="Localizzazione GPS"-->
                                    <!--<TextBlock Text="{Binding Coordinates}" Margin="12,0,0,0" HorizontalAlignment="Right" TextWrapping="NoWrap" />-->
                                </StackPanel>
                                <StackPanel Grid.Row="1" Grid.Column="3">
                                    <TextBlock Text="{Binding Path=Data, Converter={StaticResource MyDateTimeToStringConverter}, ConverterParameter=\{0:M\}}" HorizontalAlignment="Right" TextWrapping="NoWrap" Margin="12,0,0,0" />
                                    <!--, Converter={StaticResource DateTimeConverter}-->
                                </StackPanel>                                
                                <!--<CheckBox Grid.Row="0" Grid.Column="3" IsEnabled="False" Margin="-10,-10,-10,-10" IsChecked="{Binding FillUp}" HorizontalAlignment="Right" />-->
                                <!--<Button Grid.Row="1" Grid.Column="3" x:Name="btnDelete" Style="{StaticResource DeleteButtonStyle}"  Width="55" Height="55" Margin="0,-12,0,0" HorizontalAlignment="Right" Click="btnDelete_Click" />-->

                                <toolkit1:ContextMenuService.ContextMenu>
                                    <toolkit1:ContextMenu Name="MyContextMenu">
                                        <toolkit1:MenuItem x:Name="ContextMenuItemGPS" Header="locate on the map" Click="LocalizeItem_Click" CommandParameter="{Binding Coordinates}" />
                                        <toolkit1:MenuItem x:Name="ContextMenuItemDelete" Header="remove supply" Click="DeleteItem_Click" CommandParameter="{Binding SupplyId}" /> <!--Command="Delete" CommandParameter="{Binding SupplyId}"-->
                                    </toolkit1:ContextMenu>
                                </toolkit1:ContextMenuService.ContextMenu>
                            </Grid>
                        </DataTemplate>
                    </ListBox.ItemTemplate>
                </ListBox>
            </controls:PivotItem>

            <controls:PivotItem x:Name="PivotItem3MainPage" Header="{Binding Path=LocalizedResources.PivotItem3MainPage}">
                <!-- Maps -->
                <BingMap:Map Name="bingMap">
                    <!--<Maps:MapItemsControl ItemsSource="{Binding Pushpins}">
                        <Maps:MapItemsControl.ItemTemplate>
                            <DataTemplate>
                                <Maps:Pushpin Location="{Binding Location}" 
                                    Template="{StaticResource PushpinControlTemplate1}">
                                </Maps:Pushpin>
                            </DataTemplate>
                        </Maps:MapItemsControl.ItemTemplate>
                    </Maps:MapItemsControl>-->
                </BingMap:Map>
            </controls:PivotItem>

            <controls:PivotItem Header="about">
                <Grid>
                    <Grid.RowDefinitions>
                        <RowDefinition Height="200" />
                        <RowDefinition Height="40" />
                        <RowDefinition Height="40" />
                        <!--<RowDefinition Height="200" />-->
                    </Grid.RowDefinitions>
                    <Grid.ColumnDefinitions>
                        <ColumnDefinition />
                    </Grid.ColumnDefinitions>
                    <Button x:Name="AboutMe" Grid.Row="0" Grid.Column="0" Height="150" Margin="0" Padding="0" Click="Button_Click">
                        <Button.Background>
                            <ImageBrush ImageSource="Images/LogoAppWP7.png"></ImageBrush>
                        </Button.Background>
                    </Button>
                    <TextBlock Grid.Row="1" Grid.Column="0" Text="Save Fuel 2.0.0" TextWrapping="Wrap" HorizontalAlignment="Center" FontSize="24" FontWeight="Bold" />
                    <TextBlock Grid.Row="2" Grid.Column="0" Text="Developed By A4cc0st4" TextWrapping="Wrap" HorizontalAlignment="Center"></TextBlock>
                    <!--<HyperlinkButton Grid.Row="3" Grid.Column="0" NavigateUri="http://aaccostatech.wordpress.com/">
                        <HyperlinkButton.Background>
                            <ImageBrush ImageSource="Images/LogoAppWP7.png"></ImageBrush>
                        </HyperlinkButton.Background>
                    </HyperlinkButton>-->
                    <!--<Button Grid.Row="3" Grid.Column="0" Click="Button_Click" Content="Follow me!" />-->                    
                </Grid>


            </controls:PivotItem>
            
        </controls:Pivot>


        <StackPanel Visibility="Collapsed">
            <TextBlock x:Name="ErrorMessage" Text="{Binding Path=LocalizedResources.ErrorMessage}"></TextBlock>
            <TextBlock x:Name="GeoPositionStatus_Disable" Text="{Binding Path=LocalizedResources.GeoPositionStatus_Disable}"></TextBlock>
            <TextBlock x:Name="GeoPositionStatus_Initializing" Text="{Binding Path=LocalizedResources.GeoPositionStatus_Initializing}"></TextBlock>
            <TextBlock x:Name="GeoPositionStatus_NoData" Text="{Binding Path=LocalizedResources.GeoPositionStatus_NoData}"></TextBlock>
            <TextBlock x:Name="GeoPositionStatus_Ready" Text="{Binding Path=LocalizedResources.GeoPositionStatus_Ready}"></TextBlock>

            <TextBlock x:Name="LastPositioneRetrieved" Text="{Binding Path=LocalizedResources.LastPositioneRetrieved}"></TextBlock>
            <TextBlock x:Name="GPSDeviceDisabled" Text="{Binding Path=LocalizedResources.GPSDeviceDisabled}"></TextBlock>
            <TextBlock x:Name="At" Text="{Binding Path=LocalizedResources.At}"></TextBlock>
            
            <TextBlock x:Name="ErrorReadTotalDistance" Text="{Binding Path=LocalizedResources.ErrorReadTotalDistance}"></TextBlock>
            <TextBlock x:Name="ErrorReadPushpin" Text="{Binding Path=LocalizedResources.ErrorReadPushpin}"></TextBlock>
            <TextBlock x:Name="ErrorReadRefueling" Text="{Binding Path=LocalizedResources.ErrorReadRefueling}"></TextBlock>
            <TextBlock x:Name="ErrorGPSLocalization" Text="{Binding Path=LocalizedResources.ErrorGPSLocalization}"></TextBlock>
            <TextBlock x:Name="ErrorWriteTotalDistance" Text="{Binding Path=LocalizedResources.ErrorWriteTotalDistance}"></TextBlock>
            
            <TextBlock x:Name="GPSConfirmOfUsage" Text="{Binding Path=LocalizedResources.GPSConfirmOfUsage}"></TextBlock>
            
            <TextBlock x:Name="SuccessfullyInsert" Text="{Binding Path=LocalizedResources.SuccessfullyInsert}"></TextBlock>
            <TextBlock x:Name="FailedInsert" Text="{Binding Path=LocalizedResources.FailedInsert}"></TextBlock>
            
            <TextBlock x:Name="Warning" Text="{Binding Path=LocalizedResources.Warning}"></TextBlock>
            <TextBlock x:Name="VolumeMeasure" Text="{Binding Path=LocalizedResources.VolumeMeasure}"></TextBlock>

            <TextBlock x:Name="NoGPSCoordinatesRetrived" Text="{Binding Path=LocalizedResources.NoGPSCoordinatesRetrived}"></TextBlock>
            <TextBlock x:Name="ErrorLocalization" Text="{Binding Path=LocalizedResources.ErrorLocalization}"></TextBlock>
            <TextBlock x:Name="DeleteRefuelMessage" Text="{Binding Path=LocalizedResources.DeleteRefuelMessage}"></TextBlock>
            <TextBlock x:Name="ErrorDeletingRefuelMessage" Text="{Binding Path=LocalizedResources.ErrorDeletingRefuelMessage}"></TextBlock>
        </StackPanel>
    </Grid>
    
    <!--Codice di esempio che illustra l'utilizzo di ApplicationBar-->
    <phone:PhoneApplicationPage.ApplicationBar>
        <shell:ApplicationBar IsVisible="True" IsMenuEnabled="True">
            <!--<shell:ApplicationBarIconButton x:Name="Calculate" IsEnabled="True" IconUri="Images/Icons/dark/appbar.feature.settings.rest.png" Text="Calcola" Click="Calculate_Click" />-->
            <shell:ApplicationBarIconButton x:Name="Save" IconUri="Images/Icons/dark/appbar.save.rest.png" Text="Save" Click="Save_Click" />
            <!--<shell:ApplicationBarIconButton x:Name="Privacy" IconUri="Images/privacy.rest.png" Text="Privacy" />
            <shell:ApplicationBarIconButton x:Name="Guida" IconUri="Images/Icons/dark/appbar.questionmark.rest.png" Text="Guida" />-->
            <shell:ApplicationBar.MenuItems>
                <shell:ApplicationBarMenuItem x:Name="MenuItemConfiguration" Text="configurations" Click="Configuration_Click" />
                <shell:ApplicationBarMenuItem x:Name="MenuItemPrivacy" Text="privacy" Click="Privacy_Click" />
                <shell:ApplicationBarMenuItem x:Name="MenuItemGuide" Text="guide" Click="Guide_Click" />
                <!--<shell:ApplicationBarMenuItem Text="Cancella database"/>-->
                <!--<shell:ApplicationBarMenuItem Text="Esporta database"/>-->
            </shell:ApplicationBar.MenuItems>
        </shell:ApplicationBar>
    </phone:PhoneApplicationPage.ApplicationBar>

</phone:PhoneApplicationPage>